package com.cloudweb.oa.module.desktop;

import cn.js.fan.util.ErrMsgException;
import cn.js.fan.util.StrUtil;
import com.redmoon.oa.visual.FormDAO;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

public class DesktopCardUtil {
    String formCode = "config_card";

    public List<DesktopCard> list(long portalId) {
        List<DesktopCard> list = new ArrayList<>();
        String sql = "select id from form_table_" + formCode + " where portal_id=" + portalId + " and is_show=1 order by orders";
        FormDAO fdao = new FormDAO();
        try {
            Vector<FormDAO> v = fdao.list(formCode, sql);
            for (FormDAO formDAO : v) {
                DesktopCard desktopCard = new DesktopCard();
                desktopCard.setName(formDAO.getFieldValue("name"));
                desktopCard.setTitle(formDAO.getFieldValue("title"));
                desktopCard.setCardType(formDAO.getFieldValue("card_type"));
                desktopCard.setMenuItem(formDAO.getFieldValue("menu_item"));
                desktopCard.setStartVal(StrUtil.toInt(formDAO.getFieldValue("start_val"), 0));
                desktopCard.setLink("1".equals(formDAO.getFieldValue("is_link")));
                desktopCard.setUrl(formDAO.getFieldValue("url"));
                desktopCard.setUnit(formDAO.getFieldValue("unit"));
                desktopCard.setBgColor(formDAO.getFieldValue("bg_color"));
                desktopCard.setIcon(formDAO.getFieldValue("icon_font"));
                desktopCard.setModuleCode(formDAO.getFieldValue("module_code"));
                desktopCard.setRoles(formDAO.getFieldValue("roles"));
                list.add(desktopCard);
            }
        } catch (ErrMsgException e) {
            e.printStackTrace();
        }
        return list;
    }
}
